package tw.asap.plus.ui.custom;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import tw.asap.plus.R;
import tw.asap.plus.entity.CartBean;
import tw.asap.plus.entity.response.OrderDetail;

/**
 * Created by Yax.
 * Date: 15/11/15
 * Time: 上午6:04
 * Description:
 */
public class SimpleGoodsItem extends LinearLayout {
    @InjectView(R.id.goods_name)
    TextView goodsName;
    @InjectView(R.id.goods_num)
    TextView goodsNum;
    @InjectView(R.id.goods_price)
    TextView goodsPrice;

    public SimpleGoodsItem(Context context) {
        super(context);
        initViews(context);
    }

    public SimpleGoodsItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews(context);
    }

    public SimpleGoodsItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initViews(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public SimpleGoodsItem(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initViews(context);
    }

    public void initViews(Context context) {
        View goodsItem = LayoutInflater.from(context).inflate(R.layout.item_goods_simple, this);
        ButterKnife.inject(goodsItem);
    }

    public void setItemEntity(OrderDetail.ItemsEntity entity) {
        goodsName.setText(entity.getTitle());
        goodsNum.setText("x".concat(entity.getNums()));
        String price = String.format("%d", Integer.parseInt(entity.getPrice()) / 100);
        goodsPrice.setText("$".concat(price));
    }

    public void setGoodsInfo(CartBean cartBean) {
        goodsName.setText(cartBean.goodsInfo.itemEntity.getTitle());
        goodsNum.setText("x".concat(cartBean.item_nums));
        String price = String.format("%d", Integer.parseInt(cartBean.goodsInfo.itemEntity.getPrice()) / 100);
        goodsPrice.setText("$".concat(price));
    }
}
